import threading
from controller.browser import Browser
from PyQt5.QtCore import QThread, pyqtSignal


# 创建一个工作线程类
class WorkerThread(QThread):
    update_signal = pyqtSignal(str)  # 定义信号

    def __init__(self, task_type, conditions):
        """
        :param task_type: 暂停、开始
        :param conditions: 任务条件
        """
        super().__init__()
        self.task_type = task_type
        self.conditions = conditions
        self.switchs = conditions[-1]  # 线程开关

    def run(self):
        print(1)
        self.strts_task()

    def strts_task(self):
        """多线程启动任务"""
        print(2)
        if self.task_type == 0:
            return  # 任务暂停，退出循环
            # while self.paused:  # 暂停时进入循环，等待恢复
            #     time.sleep(0.1)  # 短暂休眠，避免CPU占用过高
        else:
            # 任务开始
            bw = Browser(self.conditions)
            if self.switchs == 0:  # 开启自动化
                bw.manage()

